float3 LightPosition;
float3 CameraPosition;

float4 DiffuseColor;
float3 EmissiveColor;	
float3 AmbientColor;			
float4 SpecularColor;

float4 Booleans01;				// x = Diffuse

// Structs
struct VS_OUTPUT
{
    float4 position				: POSITION;
	float2 textureCoords		: TEXCOORD0;
	float3 positionW			: TEXCOORD1;
	float3 normalW				: TEXCOORD2;
	float3 tangentW				: TEXCOORD3;
	float3 binormalW			: TEXCOORD4;
};

// Samplers
sampler2D DiffuseSampler		: register(s0);
sampler2D BumpSampler			: register(s1);
sampler2D SpecularSampler		: register(s2);

// Shaders
float4 main(VS_OUTPUT In) : COLOR
{
	float3 baseColor = 1;
	float3 normalW = normalize(In.normalW);

	// Bump
	if (Booleans01.y == 1.0f)
	{
		float3 tangentW = In.tangentW;
		float3 binormalW = In.binormalW;
	    float3 normalSample = tex2D(BumpSampler, In.textureCoords).rgb;

		float3x3 bumpMatrix;
		bumpMatrix[0] = In.tangentW;
		bumpMatrix[1] = In.binormalW;
		bumpMatrix[2] = normalW;

		normalW = normalize(normalW + mul(normalSample, bumpMatrix));
	}

	if (Booleans01.x == 1.0f)
		baseColor = tex2D(DiffuseSampler, In.textureCoords).rgb;

	// Diffuse Lighting
	float3 lightDirectionW = normalize(LightPosition - In.positionW);
	float ndl = max(0, dot(normalW, lightDirectionW));
	float3 diffuse = DiffuseColor.rgb * ndl;

	// Specular Lighting	
	float3 specularColor = SpecularColor.rgb;
	float3 viewDirectionW = normalize(CameraPosition - In.positionW);
	float3 reflectionVector = normalize(reflect(-lightDirectionW, normalW));
	float specComp = pow(saturate(dot(reflectionVector, viewDirectionW)), SpecularColor.a);

	if (Booleans01.z == 1.0f)
		specularColor += tex2D(SpecularSampler, In.textureCoords).rgb;

	float3 specular = specularColor * specComp;
	
	// Final
	return float4(saturate(saturate(diffuse +  EmissiveColor) + AmbientColor) * baseColor + specular, DiffuseColor.a);
}